﻿function prefixImageUrl(url)
{
    if (url.indexOf("http://") == -1)
    {
        url = "http://cover.carrefour.com.cn/" + url;
    }
    return url;
}

function addweibosharebtn(_title,picurl)
{
    /*if (picurl.indexOf("http://") == -1)
    {
        picurl = "http://cover.carrefour.com.cn/" + picurl;
        alert(picurl);
    }*/
    // alert(_title);
    if ( _title == undefined )
    {
        _title = '家乐福“冠军宝贝在我家—2013#快乐宝宝帮#大赛”开赛！万元大奖我来了！猛戳>>>http://cover.carrefour.com.cn';
    }

    var _w = 86, _h = 50;
    var param = {
        url: location.href,
        type: '6',
        count: '0', /**是否显示分享数，1显示(可选)*/
        appkey: '1205039490', /**您申请的应用appkey,显示分享来源(可选)*/
        title: _title, /**分享的文字内容(可选，默认为所在页面的title)*/
        //pic: picurl, /**分享图片的路径(可选)*/
        ralateUid: '2026014915', /**关联用户的UID，分享微博会@该用户(可选)*/
        language: 'zh_cn', /**设置语言，zh_cn|zh_tw(可选)*/
        rnd: new Date().valueOf()
    }
    var temp = [];
    for (var p in param)
    {
        temp.push(p + '=' + encodeURIComponent(param[p] || ''))
    }
    document.write('<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&') + '" width="' + _w + '" height="' + _h + '"></iframe>')
}

function addweiboinvitebtn()
{
    var _w = 86, _h = 50;
    var param = {
        url: location.href,
        type: '6',
        count: '0', /**是否显示分享数，1显示(可选)*/
        appkey: '1205039490', /**您申请的应用appkey,显示分享来源(可选)*/
        title: '我参加了家乐福"冠军宝贝在我家—2013快乐宝宝帮大赛"活动，你们也来参加吧，和我家宝宝组队牵手参赛赢大奖哦！猛戳： http://cover.carrefour.com.cn/ ', /**分享的文字内容(可选，默认为所在页面的title)*/
        pic: '', /**分享图片的路径(可选)*/
        ralateUid: '2026014915', /**关联用户的UID，分享微博会@该用户(可选)*/
        language: 'zh_cn', /**设置语言，zh_cn|zh_tw(可选)*/
        rnd: new Date().valueOf()
    }
    var temp = [];
    for (var p in param)
    {
        temp.push(p + '=' + encodeURIComponent(param[p] || ''))
    }
    document.write('<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&') + '" width="' + _w + '" height="' + _h + '"></iframe>')
}

function addweibosharebtnto(container, picurl)
{
    if (picurl != "")
    {
        if (picurl.indexOf("http://") == -1)
        {
            picurl = "http://cover.carrefour.com.cn/" + picurl;
        }
    }

    var _w = 86, _h = 50;
    var param = {
        url: location.href,
        type: '6',
        count: '0', /**是否显示分享数，1显示(可选)*/
        appkey: '1205039490', /**您申请的应用appkey,显示分享来源(可选)*/
        title: '家乐福“冠军宝贝在我家—2013#快乐宝宝帮#大赛”开赛！万元大奖我来了！猛戳>>>http://cover.carrefour.com.cn', /**分享的文字内容(可选，默认为所在页面的title)*/
        pic: picurl, /**分享图片的路径(可选)*/
        ralateUid: '2026014915', /**关联用户的UID，分享微博会@该用户(可选)*/
        language: 'zh_cn', /**设置语言，zh_cn|zh_tw(可选)*/
        rnd: new Date().valueOf()
    }
    var temp = [];
    for (var p in param)
    {
        temp.push(p + '=' + encodeURIComponent(param[p] || ''))
    }
    $(container).html("");
    $(container).append('<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&') + '" width="' + _w + '" height="' + _h + '"></iframe>');
    // document.write('<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&') + '" width="' + _w + '" height="' + _h + '"></iframe>')
}

$(document).ready(function ()
{
    var divWeiboSharebtn = $('<div id="divWeiboSharebtn" style="position:absolute; display:none;">');
    $("body").append(divWeiboSharebtn);

    $("img.wbshare").mouseenter(function ()
    {
        var top = $(this).offset().top;
        var left = $(this).offset().left;
        $("#divWeiboSharebtn").css("top", top).css("left", left).css("display", "");
        addweibosharebtnto($("#divWeiboSharebtn"), $(this).attr("src"));
    });
});

function openwindowshare(title, url, pic)
{
    
    var sinaurl = "http://service.weibo.com/share/share.php?ralateUid=2026014915&language="
    if( url != "" )
    {
        sinaurl += "&url=" + encodeURIComponent(url);
    }
    if( title != "" )
    {
        sinaurl += "&title=" + encodeURIComponent(title);
    }
    if( pic != "" )
    {
        sinaurl += "&pic=" + encodeURIComponent(prefixImageUrl(pic));
    }

    window.open(sinaurl);       
}